<?php
/*
Plugin Name: URL跳转
Plugin URI: https://www.beizigen.com/3391.html
Description: 自动更换文章内超链接为本地跳转URL
Version: 3.1.1
Author: 背字根
Author URI: https://www.beizigen.com/
Text Domain: gourl
License: GPL v3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
require_once('functions.php');
require_once('control.php');

//添加菜单
add_action('admin_menu', function() {
	add_options_page('URL跳转', 'URL跳转', 'administrator', 'gourl', 'gourl_control');
});
//插件页面设置链接
add_filter('plugin_action_links', function($links, $file) {
	if($file == plugin_basename(__FILE__)) {
		array_unshift($links, '<a href="options-general.php?page=gourl">管理</a>');
	}
	return $links;
}, 10, 2);
//激活插件时执行
function gourl_activation() {
	global $wpdb, $wp_rewrite;
	$charset = $wpdb->get_charset_collate();
	if(!function_exists('dbDelta')) {
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
	}

	//创建URL表
	dbDelta("CREATE TABLE IF NOT EXISTS `gourls` (
		`ID` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
		`code` VARCHAR(16) NOT NULL UNIQUE,
		`url` TEXT NOT NULL,
		`note` TEXT NOT NULL
	) $charset;");

	$wp_rewrite->flush_rules();
}
register_activation_hook(__FILE__, 'gourl_activation');

//停用插件时执行
function gourl_deactivation() {
}
register_deactivation_hook(__FILE__, 'gourl_deactivation');

//删除插件时执行
function gourl_uninstall() {
}
register_uninstall_hook(__FILE__, 'gourl_uninstall');
?>
